package com.mms.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.mms.entity.FollowUp;
import com.mms.util.JdbcUtils;

public class FollowUpMapperImpl implements FollowUpMapper {

	@Override
	public void insert(FollowUp newFollowUp, Connection conn) {
		String sql1 = "INSERT INTO followup(cust_id, follow_up_username, follow_up_date, follow_up_note, customer_state) VALUES(?, ?, ?, ?, ?)";
		PreparedStatement stmt = null;
		try {
			stmt = conn.prepareStatement(sql1);
			stmt.setInt(1, newFollowUp.getCustId());
			stmt.setString(2, newFollowUp.getFollowUpUsername());
			// 因为setDate方法需要的是java.sql.Date这个类型，所以需要把java.util.Date转成java.sql.Date
			java.sql.Date date = new java.sql.Date(newFollowUp.getFollowUpDate().getTime());
			stmt.setDate(3, date);
			stmt.setString(4, newFollowUp.getFollowUpNote());
			stmt.setString(5, newFollowUp.getCustomerState().name());
			stmt.executeUpdate();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		} finally {
			JdbcUtils.close(stmt);
		}

	}

}
